/*
利用回调函数实现对任意类型的数组排序
*/
#include <stdio.h>
int compare_int(char *a, char *b)
{
    if (*a == *b)
    {
        return 0;
    }
    else if (*a < *b)
    {
        return -1;
    }
    else
    {
        return 1;
    }
}

void swap(char *i, char *j, int size_element)
{
    char x;
    while (size_element-- > 0)
    {
        x = *i;
        *i++ = *j;
        *j++ = x;
    }
}

void fun_sort(char *first, int n_num, int size_element, int (*compare)(char *, char *))
{
    char *i, *j, *last;
    last = first + (n_num - 1) * size_element;
    for (i = first; i < last; i += size_element)
    {
        for (j = i + size_element; j <= last; j += size_element)
        {
            if (compare_int(i, j) > 0)
            {
                swap(i, j, size_element);
            }
        }
    }
}
int main()
{
    char str[10] = "abcfedabca";
    fun_sort(str, 10, 1, compare_int);
    puts(str);
    return 0;
}